home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr31 / rle8_sc.zip / RLE8.DOC < prev    next >
Text File  |  1993-05-14  |  3KB  |  94 lines

  1.  
  2. Run Length Encoding compressor program 8 bit header version
  3.  
  4. Written by Shaun Case 1991 in Borland C++ 2.0
  5.                               with sizeof (int) == 2
  6.  
  7. This program and its source code are Public Domain.
  8. This program should be portable to any machine with
  9. 2 byte short ints and 8 bit bytes, if you patch the
  10. filename stuff, which is ms-dos specific.
  11.  
  12.  
  13. What is run length encoding?
  14.  
  15. Run Length Encoding, also known as RLE, is a method of compressing data
  16. that has a lot of "runs" of bytes (or bits) in it.  A "run" is a series
  17. of bytes that are all the same. For instance, the string "THIS IS A
  18. VEEEEEEEEEEEEEEEEEEEEEEEERY INTERESTING SENTENCE" has a run of 23 'E's
  19. in it.  This could be compressed in the following manner:
  20.  
  21. THIS IS A V23ERY INTERESTING SENTENCE
  22.  
  23. resulting in a savings of 20 characters.  A further savings of one
  24. character can be realized if the sequence "23" is replaced by a single
  25. byte with the value 23.
  26.  
  27. However, if the text to be encoded is arbitrary, then it may contain
  28. numbers as well as letters, and bytes of all possible values.  For this
  29. reason, there must be some way to let the decoder know when a compressed
  30. run is encountered, and when a sequence to be passed straight through is
  31. encountered.  For this reason, the following file format was used:
  32.  
  33.  
  34. ========= tech info =========
  35.  
  36. 8 bit header version.
  37.  
  38. File format:
  39.  
  40. 13 byte original filename, followed by
  41.  
  42. [ 8 bit header + data ][ 8 bit header + data ][ 8 bit header + data ]
  43. etc..
  44.  
  45. header:
  46.  
  47.   bit 7         : 1 if following byte is a run
  48.   bit 6 - 0     : legnth of run (max 127, min 3)
  49.  
  50. data: 1 byte : which character run consists of
  51.  
  52. *** OR ***
  53.  
  54. header:
  55.  
  56.   bit 7         : 0 if following bytes are sequence
  57.   bit 6 - 0     : legnth of sequence (max 127)
  58.  
  59. data:  (header AND 0x7F) bytes of data
  60.                 : data bytes copied to output stream unchanged
  61.  
  62. ===============================
  63.  
  64. bugs:
  65.  
  66.         None known
  67.  
  68.  
  69. Nasty features :
  70.  
  71.         1)  When encoder reaches max run length, it is written
  72.             out correctly, but is followed by a 1 length run of
  73.             the next byte.  Odd.  Reason unknown.
  74.  
  75.         2)  Better compression could be achieved by having min
  76.             compression length and sequence length understood
  77.             to be 2.  This would allow an "understood" multiplication
  78.             of the seq_len or run_len by 2, since 1 is never used,
  79.             allowing sequences of 254 bytes.  This is not likely
  80.             to give much better compression in most cases,
  81.             and is left as an exercise for the reader.
  82.  
  83.             Implementing this requires fixing 1 above, too.
  84.  
  85.  
  86.  
  87.  
  88. Author:  atman%ecst.csuchico.edu@RELAY.CS.NET (internet)
  89.          1@9651                               (WWIVnet)
  90.          atman of 1:119/666.0                 (fidonet)
  91.  
  92.  
  93. Tell me hi if you use this program!
  94.